package com.wd.health.view.activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;

import com.gyf.immersionbar.ImmersionBar;
import com.wd.health.R;
import com.wd.health.view.fragment.wzysfragment.WzFragment01;
import com.wd.health.view.fragment.wzysfragment.WzFragment02;
import com.wd.health.view.fragment.wzysfragment.WzFragment03;
import com.wd.health.view.fragment.wzysfragment.WzFragment04;
import com.wd.health.view.fragment.wzysfragment.WzFragment05;
import com.wd.health.view.fragment.wzysfragment.WzFragment06;
import com.wd.health.view.fragment.wzysfragment.WzFragment07;
import com.wd.health.view.fragment.wzysfragment.WzFragment08;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class WzysActivity extends AppCompatActivity {

    private TabLayout tl;
    private ViewPager vp;
    private List<Fragment> flist = new ArrayList<>();
    private List<String> slist = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImmersionBar.with(this).init();
        setContentView(R.layout.activity_wzys);
        initView();
        initData();
    }

    private void initData() {
        flist.add(new WzFragment01());
        flist.add(new WzFragment02());
        flist.add(new WzFragment03());
        flist.add(new WzFragment04());
        flist.add(new WzFragment05());
        flist.add(new WzFragment06());
        flist.add(new WzFragment07());
        flist.add(new WzFragment08());
        slist.add("内科");
        slist.add("眼科");
        slist.add("骨科");
        slist.add("小儿科");
        slist.add("传染病科");
        slist.add("皮肤科");
        slist.add("耳鼻喉科");
        slist.add("精神病科");
        vp.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
        tl.setupWithViewPager(vp);
        Intent intent = getIntent();
        int id = intent.getIntExtra("id", 0);
        if (id==7){
            vp.setCurrentItem(0);
        }else if (id==4){
            vp.setCurrentItem(1);
        }else if (id==2){
            vp.setCurrentItem(2);
        }else if (id==5){
            vp.setCurrentItem(3);
        }else if (id==12){
            vp.setCurrentItem(4);
        }else if (id==9){
            vp.setCurrentItem(5);
        }else if (id==6){
            vp.setCurrentItem(6);
        }else if (id==11){
            vp.setCurrentItem(7);
        }
    }

    private void initView() {
        tl = findViewById(R.id.tl_wzys);
        tl.setSelectedTabIndicator(0);
        vp = findViewById(R.id.vp_wzys);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            return flist.get(position);
        }

        @Override
        public int getCount() {
            return flist.size();
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return slist.get(position);
        }
    }
}